package com.itqf.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/10/10
 * @Time: 下午4:47
 */
@ControllerAdvice  //处理异常
public class MyExceptionHandler {


    @ExceptionHandler({RuntimeException.class})//异常类型
    @ResponseBody
    public  Map<String,Object>  exception(RuntimeException e){
        e.printStackTrace();
        Map<String,Object> map = new HashMap<>();
        map.put("code","-1");//
        map.put("msg",e.getMessage());

        return  map;
    }


//
//    @ExceptionHandler({RuntimeException.class})
//    public  String  exception1(RuntimeException e, Model model){
//        model.addAttribute("msg",e.getMessage());
//
//        return  "message.jsp";
//    }

}
